package com.crystal.jcms.frament;

import com.crystal.jcms.shpz.R;
import com.crystal.jcms.utils.SpUtils;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;

public class MenuPopup extends PopupWindow {

	public Button btnCamera, btnPhoto, btnCancel;

	public MenuPopup(final Activity context) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View contentView = inflater.inflate(R.layout.popup_menu, null);
		btnCamera = (Button) contentView.findViewById(R.id.btnCamera);
		btnPhoto = (Button) contentView.findViewById(R.id.btnPhoto);
		btnCancel = (Button) contentView.findViewById(R.id.btnCancel);

		contentView.setFocusable(true);
		contentView.setFocusableInTouchMode(true);
		int iHeight = Integer.valueOf(SpUtils.get(context, "AppHeight", 0).toString());
		int iWidth = Integer.valueOf(SpUtils.get(context, "AppWidth", 0).toString());
		
		// 设置SelectPicPopupWindow的View
		this.setContentView(contentView);
		// 设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(iWidth);
		// 设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(iHeight);
		// 设置SelectPicPopupWindow弹出窗体可点击
		this.setFocusable(true);
		this.setOutsideTouchable(false);
		// 刷新状态
		this.update();
		// 实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(0000000000);
		// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
		this.setBackgroundDrawable(dw);
		// mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
		// 设置SelectPicPopupWindow弹出窗体动画效果
		this.setAnimationStyle(R.style.MenuAnimationFade);
	}

	/**
	 * 显示popupWindow
	 * 
	 * @param parent
	 */
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			// 以下拉方式显示popupwindow
			// this.showAsDropDown(parent);
			this.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
		} else {
			this.dismiss();
		}
	}


}
